package com.yuyou.activity.group.service.service.impl;

import java.util.Date;
import java.util.List;

import com.yuyou.activity.group.service.vo.resp.RespActivityGroupBuyOrderListVo;
import com.yuyou.activity.group.service.vo.resp.RespActivityGroupBuyOrderVo;
import com.yuyou.activity.group.service.vo.resp.RespActivityGroupSPDetailUser;

import com.yuyou.activity.util.bean.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yuyou.activity.group.service.entity.ActivityGroupbuyOrder;
import com.yuyou.activity.group.service.mapper.ActivityGroupbuyOrderMapper;
import com.yuyou.activity.group.service.service.IActivityGroupbuyOrderService;
import com.yuyou.activity.util.bean.ResBoolSimpleInfo;
import com.yuyou.activity.util.enums.ActivityGroupBuyOrderEnums;
import com.yuyou.activity.util.util.OrderIdUtil;
import com.yuyou.activity.util.util.Sequence;

@Service
public class ActivityGroupbuyOrderServiceImpl implements IActivityGroupbuyOrderService {

    @Autowired
    private ActivityGroupbuyOrderMapper mapper;

    @Override
    public int deleteByPrimaryKey(Long activityGroupbuyOrderId) {
        return mapper.deleteByPrimaryKey(activityGroupbuyOrderId);
    }

    @Override
    public int insert(ActivityGroupbuyOrder record) {
    	record.setActivityGroupbuyOrderId(Sequence.getSequence().nextId());
    	record.setCreateTime(new Date());
        return mapper.insert(record);
    }

    @Override
    public ActivityGroupbuyOrder selectByPrimaryKey(Long activityGroupbuyOrderId) {
        return mapper.selectByPrimaryKey(activityGroupbuyOrderId);
    }

    @Override
    public int updateByPrimaryKeySelective(ActivityGroupbuyOrder record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<ActivityGroupbuyOrder> findNotUpdateUser() {
        return mapper.findNotUpdateUser();
    }

    @Override
    public List<ActivityGroupbuyOrder> getNeedSyncOrder() {
        return mapper.getNeedSyncOrder();
    }

    @Override
    public void updateStatusByList(List<ActivityGroupbuyOrder> list, Integer tag) {
        if(tag == 1){
            mapper.updateNoticeStatusByList(list);
        }else if(tag == 2){
            mapper.updateSynceStatusByList(list);
        }
    }

    @Override
    @Transactional
    public void udateStatus(Long id, Integer status) {
        if(id != null){
            ActivityGroupbuyOrder order = new ActivityGroupbuyOrder();
            order.setActivityGroupbuyOrderId(id);
            order.setIsNotice(status);
            this.updateByPrimaryKeySelective(order);
        }
    }

    @Override
    public List<ActivityGroupbuyOrder> findByGroupId(Long groupId) {
        return mapper.findByGroupId(groupId);
    }

	@Override
	public List<ActivityGroupbuyOrder> findSuccByOpenId(String openId) {
		return mapper.findSuccByOpenId(openId);
	}

	@Override
	public ResBoolSimpleInfo<String> add(ActivityGroupbuyOrder record) {

		record.setOrderId(OrderIdUtil.getSPOrderIdID());
		record.setPayStatus(ActivityGroupBuyOrderEnums.payStatus.INIT.getValue());
		record.setIsNotice(0);
		
		this.insert(record);
		return ResBoolSimpleInfo.getSuccessInfo();
	}

    @Override
    public List<RespActivityGroupSPDetailUser> selectUserListByGroupBugId(String projectCode, Long activityGroupId) {
        return mapper.selectUserListByGroupBugId(projectCode , activityGroupId);
    }

    @Override
    public List<RespActivityGroupBuyOrderVo> myOrder(String projectCode, String openId) {
        return mapper.myOrder(projectCode , openId);
    }

    @Override
    public void updateSyncById(Long id , Integer isSync) {
        mapper.updateSyncById(id, isSync);
    }

    @Override
    public List<ActivityGroupbuyOrder> getAllNeedCheckOrder(Date bigTime, Date smallTime) {
        return mapper.getAllNeedCheckOrder(bigTime , smallTime);
    }

    @Override
    public List<RespActivityGroupBuyOrderListVo> getAllUserOrder(Pagination<RespActivityGroupBuyOrderListVo> queryPgn) {
        return mapper.getAllUserOrder(queryPgn);
    }

    @Override
    public Integer getAllUserOrderCount(Pagination<RespActivityGroupBuyOrderListVo> queryPgn) {
        return mapper.getAllUserOrderCount(queryPgn);
    }

    @Override
    public List<ActivityGroupbuyOrder> getOrderByOpenIdInGroup(String projectCode, String openId, Long activityGroupbuyId) {
        return mapper.getOrderByOpenIdInGroup(projectCode,openId,activityGroupbuyId);
    }

    @Override
    public String getChannelInOrder(String projectCode, Long activityGroupId, String openId) {
        return mapper.getChannelInOrder(projectCode , activityGroupId , openId);
    }

    @Override
	public ActivityGroupbuyOrder selectByOrderId(String projectCode,String orderId) {
		return mapper.selectByOrderId(projectCode, orderId);
	}

	@Override
	public ActivityGroupbuyOrder selectByRefundId(String projectCode, String refundId) {
		return mapper.selectByRefundId(projectCode, refundId);
	}

	@Override
	public List<ActivityGroupbuyOrder> findSuccByGroupId(Long groupId) {
		return mapper.findSuccByGroupId(groupId);
	}

}